package com.higgins.eventtracking.client.health.action;

import java.util.Date;
import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.datepicker.client.CalendarUtil;
import com.higgins.eventtracking.client.EventTrackingService;
import com.higgins.eventtracking.client.EventTrackingServiceAsync;
import com.higgins.eventtracking.client.dto.HealthAlertDTO;
import com.higgins.eventtracking.client.health.components.HealthAlertColumns;
import com.higgins.eventtracking.client.health.components.HealthAlertTable;
import com.higgins.eventtracking.client.health.fundamentals.SubTab;

public class FuelTab extends ScrollPanel implements SubTab	{
	private final EventTrackingServiceAsync greetingService = GWT
			.create(EventTrackingService.class);
	VerticalPanel verticalPanel = null;
	HorizontalPanel horizontalPanel = null;
	DailyColumns columns = null;
	FuelTable table = null;
	Button left = null;
	Button right = null;
	Label dateLabel = null;
	Date now = null;
	CalendarUtil cal;
	
	private boolean firstRun = true;
	
	public FuelTab()	{
	}
	
	public void update()	{
		if (firstRun)	
			initialise();
		
	}
	
	public void initialise()	{
		this.clear();
		now = new Date();
		verticalPanel = new VerticalPanel();
		horizontalPanel = new HorizontalPanel();
		columns = new DailyColumns();
		table = new FuelTable(columns);
		left = new Button("<-");
		right = new Button("->");
		dateLabel = new Label();

		left.addClickHandler(new ClickHandler()  {
			@Override
			public void onClick(ClickEvent event) {
				cal.addDaysToDate(now, -1);
				table.setDate(now);
				dateLabel.setText(now.toString());
			}
			
		});
		right.addClickHandler(new ClickHandler()  {
			@Override
			public void onClick(ClickEvent event) {
				cal.addDaysToDate(now, 1);	
				table.setDate(now);
				dateLabel.setText(now.toString());
			}
			
		});		
		//firstRun = false;
		horizontalPanel.add(left);
		horizontalPanel.add(dateLabel);
		horizontalPanel.add(right);
		verticalPanel.add(horizontalPanel);		// NOT NEEDED FOR YEARLY!!
		table.setDate(new Date());
		verticalPanel.add(table);
		add(verticalPanel);
		setHeight("20em");
//		setWidth("100em");
	}
}
